/*
ID: simplyz2
LANG: C
TASK: dualpal
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LEN 32
char ret[MAX_LEN];
int N, S;

int
is_valid(char *str)
{
	int i, length = strlen(str);
	for(i=0; i<length/2; i++)
		if(str[i] != str[length-i-1])
			return 0;
	return 1;
}

void
transform(int base, int num, char *rt)
{
	int length, mod;
	if(num == 0)
		return;
	transform(base, num/base, rt);
	mod = num % base;
	length = strlen(rt);
	rt[length] = mod + '0';
}

void
solve()
{
	int i, j, tm, count = 0;
	i = S;
	while(count < N) {
		++i;
		tm = 0;
		for(j=2; j<=10; j++) {
			memset(ret, 0, sizeof(ret));
			transform(j, i, ret);
			if(is_valid(ret))
				++tm;
		}
		if(tm >= 2) {
			++count;
			printf("%d\n", i);
		}
	}
}

int
main(int argc, char **argv)
{
	freopen("dualpal.in", "r", stdin);
	freopen("dualpal.out", "w", stdout);
	while(scanf("%d %d", &N, &S) != EOF) {
		solve();
	}
	return 0;
}
